package com.cskaoyan._04oop1._06static;

/**
 * @author Macro_Ray
 * @since 2024/3/7 16:15
 */
// 观察程序执行顺序
public class Demo2 {
    // 静态代码块
    static {
        System.out.println("Demo2开始初始化");
    }
    // 静态成员变量
    static Cat cat = new Cat();
    Dog dog = new Dog();

    public Demo2() {
        System.out.println("Demo2 constructor");
    }

    public static void main(String[] args) {
        System.out.println("hello world");
        Demo2 d = new Demo2();
    }

}

class Dog {
    static {
        System.out.println("Dog开始初始化");
    }

    static Demo2 demo2 = new Demo2();

    public Dog() {
        System.out.println("Dog constructor");
    }
}

class Cat {
    static {
        System.out.println("Cat开始初始化");
    }

    static Dog dog = new Dog();

    public Cat() {
        System.out.println("Cat constructor");
    }
}

